ASSUME CS:CODE,DS:DATA,SS:STACK
DATA SEGMENT
    ARRAY DB 12,20,23,34,45,78,0,0,0,0
    LENGHT DW 10
DATA ENDS

STACK SEGMENT
    INSDATA DW 0,0,0,0,0,0,0,0
STACK ENDS

CODE SEGMENT
    MAIN:
    MOV AX,DATA
    MOV DS,AX

    MOV SI,OFFSET ARRAY
    MOV BL,10
    MOV CX,6
    CALL INSERT

    MOV BL,18
    MOV CX,7
    CALL INSERT

    MOV BL,90
    MOV CX,8
    CALL INSERT

    MOV AX,4C00H
    INT 21H

    INSERT:
    PUSH CX
    PUSH SI
    MOV DI,SI
    ADD DI,CX
    
    POSITION:
    DEC DI
    LOOP POSITION
    JCXZ EXIT

    CMP [DI],BL
    JBE ELEMENT
    DEC SI
    JMP POSITION

    ELEMENT:
    MOV [DI],BL

    EXIT:
    CLD
    POP SI
    POP CX
    RET
    
INSERT ENDS
END MAIN
